package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.List;

import javax.swing.JPanel;

import bo.BusinessFigure;
import data.PaintGraph;
import data.ScaleCalculate;

/**
 * the profit graph panel
 * @author Nikolai Straessle
 *
 */
public class ProfitResPanel extends JPanel {
	
    private static final int PREF_W = 400;//set preffered width
    private static final int PREF_H = PREF_W;//set preffered height
	private static final long serialVersionUID = 1L;
	private List<BusinessFigure> aListFigure;
	private PaintGraph pGraph;
	

	/**
	 * this constructor will create a simple JPanel
	 * the method paintComponent(Graphics g) will paint all graph's on the panel
	 * @param aListFigure
	 * 		java.util.List<BusinessFigure>
	 */
	public ProfitResPanel(List<BusinessFigure> aListFigure) {
		super();
		this.aListFigure = aListFigure;
	}
	
	/**
	 * set the preffered Size of this panel
	 */
	public Dimension getPreferredSize() {
        return new Dimension(PREF_W, PREF_H);
     }

	/**
	 * Paint the Graph and points on the Panel
	 */
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		this.pGraph = new PaintGraph(aListFigure, getHeight(), getWidth(), new ScaleCalculate().yScaleProfit(aListFigure));
		Graphics2D g2 = (Graphics2D)g;
		g2.drawLine(pGraph.getGx0(), pGraph.getGy0(), getWidth() - pGraph.getGx0(), pGraph.getGy0());//x-Axis
		g2.drawLine(pGraph.getGx0(), pGraph.getGx0(), pGraph.getGx0(), getHeight() - pGraph.getGx0());//y-Axis
		g2.drawLine(pGraph.getViewX(1), pGraph.getViewY(3), pGraph.getViewX(1), pGraph.getViewY(-3));//Line Year 1
		g2.drawLine(pGraph.getViewX(2), pGraph.getViewY(3), pGraph.getViewX(2), pGraph.getViewY(-3));//Line Year 2
		g2.drawLine(pGraph.getViewX(3), pGraph.getViewY(3), pGraph.getViewX(3), pGraph.getViewY(-3));//Line Year 3
		g2.drawLine(pGraph.getViewX(4), pGraph.getViewY(3), pGraph.getViewX(4), pGraph.getViewY(-3));//Line Year 4
		g2.drawLine(pGraph.getViewX(5), pGraph.getViewY(3), pGraph.getViewX(5), pGraph.getViewY(-3));//Line Year 5
		g2.drawString("Jahr 1", pGraph.getViewX(1), pGraph.getViewY(-3));//Text Year 1
		g2.drawString("Jahr 2", pGraph.getViewX(2), pGraph.getViewY(-3));//Text Year 2
		g2.drawString("Jahr 3", pGraph.getViewX(3), pGraph.getViewY(-3));//Text Year 3
		g2.drawString("Jahr 4", pGraph.getViewX(4), pGraph.getViewY(-3));//Text Year 4
		g2.drawString("Jahr 5", pGraph.getViewX(5), pGraph.getViewY(-3));//Text Year 5
		g2.drawLine(pGraph.getViewX(1), pGraph.getProfitY(1), pGraph.getViewX(5), pGraph.getProfitY(5));//draw the graph
		g2.drawLine(pGraph.getGx0(), pGraph.getProfitY(1), pGraph.getViewX(0.1), pGraph.getProfitY(1));//draw a Line for the first step of the Graph
		g2.drawString(String.valueOf((int)pGraph.getProfitTab(1)),pGraph.getViewX(0.1), pGraph.getProfitY(1));//first step of the graph string
		g2.drawLine(pGraph.getGx0(), pGraph.getProfitY(5), pGraph.getViewX(0.1), pGraph.getProfitY(5));//draw a Line for the last step of the Graph
		g2.drawString(String.valueOf((int)pGraph.getProfitTab(5)),pGraph.getViewX(0.1), pGraph.getProfitY(5));//last step of the graph string
		g2.setColor(Color.black);//set the color of the points
		g2.fillOval(pGraph.getViewX(1) - 3, pGraph.getViewY(aListFigure.get(0).getaProfit()) - 3, 6, 6);//point of year one
		g2.drawString(String.valueOf((int)aListFigure.get(0).getaProfit()), pGraph.getViewX(1) + 3, pGraph.getViewY(aListFigure.get(0).getaProfit()));//string point one
		g2.fillOval(pGraph.getViewX(2) - 3, pGraph.getViewY(aListFigure.get(1).getaProfit()) - 3, 6, 6);//point of year two
		g2.drawString(String.valueOf((int)aListFigure.get(1).getaProfit()), pGraph.getViewX(2) + 3, pGraph.getViewY(aListFigure.get(1).getaProfit()));//string point two
		g2.fillOval(pGraph.getViewX(3) - 3, pGraph.getViewY(aListFigure.get(2).getaProfit()) - 3, 6, 6);//point of year three
		g2.drawString(String.valueOf((int)aListFigure.get(2).getaProfit()), pGraph.getViewX(3) + 3, pGraph.getViewY(aListFigure.get(2).getaProfit()));//string point three
		g2.fillOval(pGraph.getViewX(4), pGraph.getProfitY(4), 6, 6);//point of year four
		g2.drawString(String.valueOf((int)pGraph.getProfitTab(4)), pGraph.getViewX(4) + 3, pGraph.getProfitY(4) - 3);//string point four
		g2.fillOval(pGraph.getViewX(5) - 3, pGraph.getProfitY(5) - 3, 6, 6);//pint of year five
		g2.drawString(String.valueOf((int)pGraph.getProfitTab(5)), pGraph.getViewX(5) + 3, pGraph.getProfitY(5) - 3);//string point five
		
		
	}

}
